class Solution {
public:
    int maxProfit(vector<int>& p)
    {
        int sum = 0;
        for (int i = 0; i < p.size(); i++)
        {
            int j = i;
            while (j + 1 < p.size() && p[j + 1] > p[j])
            {
                sum += p[j + 1] - p[j++];
            }
            i = j;
        }
        return sum;
    }
};